home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 2.iso / STUTTGART / LANG / C / LIB / DESK / CORE / Desk / h_doc / Coord < prev    next >
Text File  |  1996-05-21  |  9KB  |  277 lines

  1. /*
  2.     ####             #    #     # #
  3.     #   #            #    #       #          The FreeWare C library for
  4.     #   #  ##   ###  #  # #     # ###             RISC OS machines
  5.     #   # #  # #     # #  #     # #  #   ___________________________________
  6.     #   # ####  ###  ##   #     # #  #
  7.     #   # #        # # #  #     # #  #    Please refer to the accompanying
  8.     ####   ### ####  #  # ##### # ###    documentation for conditions of use
  9.     ________________________________________________________________________
  10.  
  11.     File:    Coord.h
  12.     Author:  Copyright © 1992, 1993, 1994 Edouard Poor, Jason Williams
  13.                                           and Tim Browse
  14.     Version: 1.02 (02 Mar 1994)
  15.     Purpose: Coord (point and rectangle) handling functions
  16. */
  17.  
  18. #ifndef __Desk_Coord_h
  19. #define __Desk_Coord_h
  20.  
  21. #ifdef __cplusplus
  22.     extern "C" {
  23. #endif
  24.  
  25.  
  26. #ifndef __Desk_core_h
  27.     #include "Core.h"
  28. #endif
  29.  
  30. #ifndef __Desk_Wimp_h
  31.     #include "Wimp.h"
  32. #endif
  33.  
  34.  
  35.  
  36. typedef struct
  37. {
  38.   Desk_wimp_rect  screenrect;
  39.   Desk_wimp_point scroll;
  40. } Desk_convert_block;
  41.  
  42.  
  43. extern Desk_bool Desk_Coord_PointInRect( const Desk_wimp_point *point, const Desk_wimp_rect *rect);
  44. /*
  45.   Inputs:   point - the point to test
  46.             rect - the rectangle to check for containment with.
  47.   Returns:  Desk_bool_TRUE if point is in rectangle; Desk_bool_FALSE otherwise.
  48.   Purpose:  Tests whether the point is within the rectangle. If it's on the
  49.             line it's counted as in (just like in tennis).
  50.   SeeAlso:  Desk_Coord_RectContained; Desk_Coord_RectsOverlap
  51. */
  52.  
  53.  
  54.  
  55.  
  56. extern Desk_bool Desk_Coord_RectContained( const Desk_wimp_rect *InsideRect,
  57.                                   const Desk_wimp_rect *OutsideRect);
  58. /*
  59.   Inputs:   See purpose.
  60.   Returns:  Desk_bool_TRUE if InsideRect is withing OutsideRect;
  61.             Desk_bool_FALSE otherwise.
  62.   Purpose:  Test whether the InsideRect is wholly contained by the
  63.             OutsideRect.  Shared vertices/edges are considered to be inside.
  64.   SeeAlso:  Desk_Coord_PointInRect; Desk_Coord_RectsOverlap
  65.  
  66. */
  67.  
  68.  
  69.  
  70.  
  71. extern Desk_bool Desk_Coord_RectsOverlap( const Desk_wimp_rect *rect1, const Desk_wimp_rect *rect2);
  72. /*
  73.   Inputs:   rect1, rect2 - the rectangles to check for overlap.
  74.   Returns:  Desk_bool_TRUE if rectangles overlap;
  75.             Desk_bool_FALSE otherwise.
  76.   Purpose:  Checks to see if two rectangles overlap each other in any
  77.             way (includes containment).
  78.   SeeAlso:  Desk_Coord_RectsIntersect
  79. */
  80.  
  81.  
  82.  
  83.  
  84. #define Desk_Coord_RectsIntersect(r1, r2) (Desk_Coord_RectsOverlap(r1, r2) && \
  85.                                      !Desk_Coord_RectContained(r1, r2) && \
  86.                                      !Desk_Coord_RectContained(r2, r1))
  87. /*
  88.   MACRO:    Desk_bool Desk_Coord_RectsIntersect(Desk_wimp_rect *rect1, Desk_wimp_rect *rect2)
  89.  
  90.   Inputs:   rect1, rect2 - the rectangles to check for intersection
  91.   Returns:  Desk_bool_TRUE if rectangles intersect but do not contain each other;
  92.             Desk_bool_FALSE otherwise.
  93.   Purpose:  Tests if two rectangles intersect each other, but wil return
  94.             failure if either rectangle wholly contains the other one.
  95.             This is different to the behaviour of Desk_Coord_RectsOverlap.
  96.   SeeAlso:  Desk_Coord_RectsOverlap
  97. */
  98.  
  99.  
  100.  
  101.  
  102. /*K**************************************************************************
  103.  
  104. > Coordinate conversion.
  105.  
  106.   Screen <---> Work Area conversion routines.
  107.   NOTE:
  108.     "Screen Coordinates" refers to OS coordinates, with the bottom
  109.       left corner of the screen being placed at the screen origin, (0, 0)
  110.     "Work Area Coordinates" refers to Coordinates within the Window's
  111.       work area, where the (0, 0) origin is at the TOP left of the work area
  112.  
  113.   Some of these routines have been defined as macros because they are
  114.   very elementary, and are common, so efficiency will be improved by
  115.   removing the function call overhead.
  116.  
  117.   To keep compatibility with the syntax of Acorn's Desk_coords_ calls, these
  118.   macros still accept a pointer to a Desk_convert_block.
  119.  
  120. ****************************************************************************/
  121.  
  122.  
  123.  
  124. extern void Desk_Coord_WindowOrigin( Desk_wimp_point *origin, const Desk_convert_block *convert);
  125. /*
  126.   Inputs:   convert - the standard Desk_convert_block.
  127.   Outputs:  origin - the window origin, in screen coordinates.
  128.   Purpose:  Returns the origin (TOP LEFT (0, 0) corner) of the window's
  129.             work-area in screen coordinates. This can then be used as a
  130.             redraw-origin for redraws - any drawing done relative to this
  131.             origin will appear at the correct screen position regardless of
  132.             scroll bar offsets and screen position of the window.
  133.             Remember to call this at the start of each redraw - whenever the
  134.             window is moved or scrolled, the position of this origin (in
  135.             screen coordinates) will change, so it must be recalculated.
  136.   SeeAlso:  Desk_Coord_PointToScreen
  137. */
  138.  
  139.  
  140.  
  141.  
  142. #define Desk_Coord_XToScreen(X, C) \
  143.             (((X) - (C)->scroll.x) + (C)->screenrect.min.x)
  144. /*
  145.   MACRO:    int Desk_Coord_XToScreen(int xpos, Desk_convert_block *convert)
  146.  
  147.   Inputs:   xpos - the x coordinate to translate.
  148.             convert - the standard Desk_convert_block.
  149.   Returns:  The translated x coordinate.
  150.   Purpose:  Translate a x coordinate from the work-area to the screen
  151.             coordinate space.
  152.   SeeAlso:  Desk_Coord_PointToScreen; Desk_Coord_YToScreen
  153. */
  154.  
  155.  
  156.  
  157.  
  158. #define Desk_Coord_YToScreen(Y, C) \
  159.         ( ((Y) - (C)->scroll.y) + (C)->screenrect.max.y )
  160. /*
  161.   MACRO:    int Desk_Coord_YToScreen(int ypos, Desk_convert_block *convert)
  162.  
  163.   Inputs:   ypos - the y coordinate to translate.
  164.             convert - the standard Desk_convert_block.
  165.   Returns:  The translated y coordinate.
  166.   Purpose:  Translate a y coordinate from the work-area to the screen
  167.             coordinate space.
  168.   SeeAlso:  Desk_Coord_PointToScreen; Desk_Coord_XToScreen
  169. */
  170.  
  171.  
  172.  
  173.  
  174. extern void Desk_Coord_PointToScreen(Desk_wimp_point *point, const Desk_convert_block *convert);
  175. /*
  176.   Inputs:   point - a point in Work Area coords.
  177.             convert - the standard Desk_convert_block.
  178.   Outputs:  point - the same point in screen coordinates
  179.   Purpose:  Convert a work-area coordinate to a screen coordinate.
  180.   SeeAlso:  Desk_Coord_RectToScreen; Desk_Coord_XToScreen; Desk_Coord_YToScreen;
  181.             Desk_Coord_PointToWorkArea
  182. */
  183.  
  184.  
  185.  
  186.  
  187. extern void Desk_Coord_RectToScreen(Desk_wimp_rect *rect, const Desk_convert_block *convert);
  188. /*
  189.   Inputs:   rect - a rectangle in Work Area coords.
  190.             convert - the standard Desk_convert_block.
  191.   Outputs:  rect - the same rectangle in screen coordinates
  192.   Purpose:  Convert a rectangle in work-area coordinates to screen
  193.             coordinates.
  194.   SeeAlso:  Desk_Coord_PointToScreen
  195. */
  196.  
  197.  
  198.  
  199.  
  200. #define Desk_Coord_XToWorkArea(X, C) (((X)-(C)->screenrect.min.x)+(C)->scroll.x)
  201. /*
  202.   MACRO:    int Desk_Coord_XToWorkArea(int xpos, Desk_convert_block *convert)
  203.  
  204.   Inputs:   xpos - the screen x coordinate to convert.
  205.             convert - the standard Desk_convert_block.
  206.   Returns:  The x coordinate translated to work-area coordinates.
  207.   Purpose:  Convert an x coordinate from the screen coordinate space to
  208.             the work-area coordinate space.
  209.   SeeAlso:  Desk_Coord_YToWorkArea; Desk_Coord_PointToWorkArea
  210. */
  211.  
  212.  
  213.  
  214.  
  215. #define Desk_Coord_YToWorkArea(Y, C) (((Y)-(C)->screenrect.max.y)+(C)->scroll.y)
  216. /*
  217.   MACRO:    int Desk_Coord_YToWorkArea(int ypos, Desk_convert_block *convert)
  218.  
  219.   Inputs:   ypos - the screen y coordinate to convert.
  220.             convert - the standard Desk_convert_block.
  221.   Returns:  The y coordinate translated to work-area coordinates.
  222.   Purpose:  Convert an y coordinate from the screen coordinate space to
  223.             the work-area coordinate space.
  224.   SeeAlso:  Desk_Coord_XToWorkArea; Desk_Coord_PointToWorkArea
  225. */
  226.  
  227.  
  228.  
  229.  
  230. extern void Desk_Coord_PointToWorkArea(Desk_wimp_point *point,
  231.                                     const Desk_convert_block *convert);
  232. /*
  233.   Inputs:   point - a point in screen coords.
  234.             convert - the standard Desk_convert_block.
  235.   Outputs:  point - the same point in work area coords.
  236.   Purpose:  Convert a coordinate from the screen coordinate space to the
  237.             work-area coordinate space.
  238.   SeeAlso:  Desk_Coord_PointToScreen; Desk_Coord_RectToWorkArea
  239. */
  240.  
  241.  
  242.  
  243.  
  244. extern void Desk_Coord_RectToWorkArea(Desk_wimp_rect *rect, const Desk_convert_block *convert);
  245. /*
  246.   Inputs:   rect - a rectangle in screen coords.
  247.             convert - the standard Desk_convert_block.
  248.   Outputs:  rect - the same rectangle in work area coords.
  249.   Purpose:  Convert a rectangle from the screen coordinate space to the
  250.             work-area coordinate space.
  251.   SeeAlso:  Desk_Coord_PointToWorkArea; Desk_Coord_RectToScreen
  252. */
  253.  
  254.  
  255.  
  256.  
  257. extern void Desk_Coord_RectUnion(Desk_wimp_rect *dest,
  258.                               Desk_wimp_rect *src1, Desk_wimp_rect *src2);
  259. /*
  260.   Inputs:   src1, src2 - the two rectangles to find the union of.
  261.   Outputs:  dest - the rectangle structure to hold the union.
  262.   Purpose:  Find the union of two rectangles.  dest can be the same as
  263.             either src1 or src2 if you want to use this as an
  264.             accumulator.  (dest can be the same as src1 *and* src2, if
  265.             you're feeling really silly).
  266.   SeeAlso:  Desk_Coord_RectsOverlap; Desk_Coord_RectsIntersect
  267. */
  268.  
  269.  
  270.  
  271. #ifdef __cplusplus
  272. }
  273. #endif
  274.  
  275.  
  276. #endif
  277.